import { getProvinceApi } from "@/api/common";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formDataRef = ref<any>(null);
  const formState = reactive<Partial<{ areaIds: string[]; streetCode: string }>>({
    areaIds: [],
    streetCode: undefined
  });
  const areaOpts = ref<Array<Base.GeneraDataType>>([]);
  const streetOpts = ref<Array<Base.GeneraDataType>>([]);
  const getAreaOpts = () => {
    return getProvinceApi().then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        areaOpts.value = data;
      }
    });
  };
  return {
    formDataRef,
    formState,
    areaOpts,
    getAreaOpts,
    streetOpts
  };
}
